/** 表格表头 */
export const tableColumns = (t: (msg: string) => string) => [
  {
    prop: "id",
    type: "selection",
    label: t("table.selection"),
    width: 55,
    reserveSelection: true,
    fixed: "left",
  },
  {
    prop: "ID",
    label: t("table.id"),
    minWidth: 100,
  },
  {
    prop: "username",
    label: t("table.username"),
    width: 220,
    fixed: "left",
  },
  {
    prop: "store_name",
    label: t("table.store_name"),
    minWidth: 120,
  },
  {
    prop: "from_user",
    label: t("table.from_user"),
    minWidth: 120,
  },
  {
    prop: "last_join_time",
    label: t("table.last_join_time"),
    minWidth: 120,
    format: (value: number) => {
      if (!value) return "--";
      if (new Date().setHours(0, 0, 0) < value) {
        return "今日";
      }
      const data = parseInt(Date.now() / 1000 + "") - value;
      // 时分秒
      const days = Math.floor(data / (3600 * 24));
      if (days == 1) {
        return "昨日";
      } else {
        return days + "天前";
      }
    },
  },
  {
    prop: "statistics",
    label: t("table.statistics"),
    minWidth: 180,
  },
  {
    prop: "jifen",
    label: t("table.jifen"),
    minWidth: 80,
  },
  {
    prop: "mobile",
    label: t("table.mobile"),
    minWidth: 120,
  },
  {
    prop: "ip",
    label: t("table.ip"),
    minWidth: 120,
  },
  {
    prop: "reg_time",
    label: t("table.reg_time"),
    minWidth: 180,
    format: "date|YYYY-MM-DD HH:mm:ss",
  },
  {
    prop: "status",
    label: t("table.status"),
    minWidth: 120,
  },
  // {
  //   prop: 'action',
  //   label: t('table.operation'),
  //   width: 100,
  //   showOverflowTooltip: false,
  //   fixed: 'right',
  // },
];

/** 表格搜索表单 */
export const tableSearchFormItems = (t: (msg: string) => string) => [
  {
    attrs: {
      label: t("search.nickname"),
      prop: "search_key",
    },
    value: "",
    component: {
      is: "el-input",
      props: {
        placeholder: "请输入用户信息"
      },
    },
  },
  {
    attrs: {
      label: t("search.mobile"),
      prop: "mobile",
    },
    value: "",
    component: {
      is: "el-input",
      props: {
        placeholder: t("search.mobile.placeholder"),
      },
    },
  },
  {
    attrs: {
      label: t("search.store_id"),
      prop: "store_id",
    },
    value: "",
    component: {
      is: "el-select",
      props: {
        placeholder: t("search.store_id.placeholder"),
        filterable: true,
      },
    },
    childrenComponent: {
      is: "el-option",
      children: [],
    },
  },
  {
    attrs: {
      label: t("search.status"),
      prop: "status",
    },
    value: "",
    component: {
      is: "el-select",
      props: {
        placeholder: t("search.status.placeholder"),
      },
    },
    childrenComponent: {
      is: "el-option",
      children: () => [
        {
          label: t("status1"),
          value: 1,
        },
        {
          label: t("status2"),
          value: 2,
        },
        {
          label: t("status3"),
          value: 3,
        },
        {
          label: t("status4"),
          value: -1,
        },
      ],
    },
  },
  {
    attrs: {
      label: "停看天数",
      prop: "look_day",
    },
    value: [],
    component: {
      is: "f-input-range",
    },
  },
  {
    attrs: {
      label: "参与次数",
      prop: "canyu",
    },
    value: [],
    component: {
      is: "f-input-range",
    },
  },
  {
    attrs: {
      label: "红包个数",
      prop: "hongbao_num",
    },
    value: [],
    component: {
      is: "f-input-range",
    },
  },
  {
    attrs: {
      label: "红包金额",
      prop: "money",
    },
    value: [],
    component: {
      is: "f-input-range",
    },
  },
  {
    attrs: {
      label: "积分数量",
      prop: "jifen",
    },
    value: [],
    component: {
      is: "f-input-range",
    },
  },
  {
    attrs: {
      label: "邀请人数",
      prop: "yaoqing",
    },
    value: [],
    component: {
      is: "f-input-range",
    },
  },
  {
    attrs: {
      label: t("search.date"),
      prop: "date",
    },
    value: "",
    component: {
      is: "el-date-picker",
      props: {
        type: "datetimerange",
        valueFormat: "YYYY-MM-DD HH:mm:ss",
        startPlaceholder: t("search.date.start.placeholder"),
        endPlaceholder: t("search.date.end.placeholder"),
        defaultTime: [
          new Date(2000, 1, 1, 0, 0, 0),
          new Date(2000, 2, 1, 23, 59, 59),
        ],
        shortcuts: [
          {
            text: t("search.date.shortcuts0"),
            value: () => {
              const end = new Date(new Date().setHours(23, 59, 59));
              const start = new Date(new Date().setHours(0, 0, 0));
              // start.setDate(start.getDate() - 7)
              return [start, end];
            },
          },
          {
            text: t("search.date.shortcuts1"),
            value: () => {
              const end = new Date(new Date().setHours(23, 59, 59));
              const start = new Date(new Date().setHours(0, 0, 0));
              start.setDate(start.getDate() - 7);
              return [start, end];
            },
          },
          {
            text: t("search.date.shortcuts2"),
            value: () => {
              const end = new Date(new Date().setHours(23, 59, 59));
              const start = new Date(new Date().setHours(0, 0, 0));
              start.setMonth(start.getMonth() - 1);
              return [start, end];
            },
          },
          {
            text: t("search.date.shortcuts3"),
            value: () => {
              const end = new Date(new Date().setHours(23, 59, 59));
              const start = new Date(new Date().setHours(0, 0, 0));
              start.setMonth(start.getMonth() - 3);
              return [start, end];
            },
          },
        ],
      },
    },
  },
];
